/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path);
}

export function fmtDate_day(obj, dat) {
  // 日期转换
  if (!obj) {
    return
  }
  var date = new Date(Date.parse(obj.replace(/-/g, "/")));
  var y = date.getFullYear();
  var m = date.getMonth() + 1;
  m = m < 10 ? "0" + m : m;
  var d = date.getDate();
  d = d < 10 ? "0" + d : d;
  var h = date.getHours();
  h = h < 10 ? "0" + h : h;
  var minute = date.getMinutes();
  var second = date.getSeconds();
  minute = minute < 10 ? "0" + minute : minute;
  second = second < 10 ? "0" + second : second;
  let a = "";
  if (dat === "yyyy-mm-dd") {
    a = y + "-" + m + "-" + d;
  } else if (dat === "yyyy-mm-dd hh:mm") {
    a = y + "-" + m + "-" + d + ' ' + h + ':' + minute;
  } else if (dat === "yyyy-mm-dd hh:mm:ss") {
    a = y + "-" + m + "-" + d + ' ' + h + ':' + minute + ':' + second;
  }
  return a;
}
//获取默认时间
export function defaultDate(number, newTime) {
  let defaultTime = number;
  let lastTime = "";
  let time = new Date(newTime); //现在时间
  let year = time.getFullYear(); //当前年
  let lastyear = year - 1; //前一年
  let month = time.getMonth() + 1; //当前月
  let day = time.getDate(); //当前天
  let lastMonth = month - 1; //上月
  let lastDay = new Date(year, lastMonth, 0).getDate(); //上月天数
  if (month == 1) {
    if (day <= defaultTime) {
      lastTime = lastyear + "-" + 12 + "-" + (31 + day - defaultTime);
    } else {
      let newday = day - defaultTime
      if (newday < 10) {
        newday = '0' + newday
      }
      lastTime = year + "-" + month + "-" + newday;
    }
  } else {
    if (day <= defaultTime) {
      lastTime = year + "-" + lastMonth + "-" + (lastDay + day - defaultTime);
    } else {
      let newday = day - defaultTime
      if (newday < 10) {
        newday = '0' + newday
      }
      lastTime = year + "-" + month + "-" + newday;
    }
  }
  if (day < 10) {
    day = '0' + day
  }
  let nowtime = year + "-" + month + "-" + day
  let data = [lastTime, nowtime]
  return data
}
export function authorityLevelJudeg(val) {
  let text = val
  if (val == 1) {
    text = '录单岗'
  } else if (val == '2') {
    text = 'D6级'
  } else if (val == '3') {
    text = 'D5级'
  } else if (val == '4') {
    text = 'D4级'
  } else if (val == '5') {
    text = 'D3级'
  } else if (val == '6') {
    text = 'D2级'
  } else if (val == '7') {
    text = 'D1级'
  } else if (val == '8') {
    text = 'C3级'
  } else if (val == '9') {
    text = 'C2级'
  } else if (val == '10') {
    text = 'C1级'
  } else if (val == '11') {
    text = 'B3级'
  } else if (val == '12') {
    text = 'B2级'
  } else if (val == '13') {
    text = 'B1级'
  } else if (val == '14') {
    text = 'A3级'
  } else if (val == '15') {
    text = 'A2级'
  } else if (val == '16') {
    text = 'A1级'
  } else if (val == '17') {
    text = '审核通过'
  } else if (val == '100') {
    text = '出单岗'
  } else if (val == '101') {
    text = '中级审核2'
  } else if (val == '102') {
    text = '中级审核1'
  } else if (val == '103') {
    text = '高级审核2'
  } else if (val == '104') {
    text = '高级审核1'
  } else if (val == '105') {
    text = '首席审核'
  }
  return text
}

export function authorityLevelJudegShi(val) {
  let text = val
  if (val == 1) {
    text = '录单岗'
  } else if (val == '2') {
    text = 'D6级'
  } else if (val == '3') {
    text = 'D5级'
  } else if (val == '4') {
    text = 'D4级'
  } else if (val == '5') {
    text = 'D3级'
  } else if (val == '6') {
    text = 'D2级'
  } else if (val == '7') {
    text = 'D1级'
  } else if (val == '8') {
    text = 'C3级'
  } else if (val == '9') {
    text = 'C2级'
  } else if (val == '10') {
    text = 'C1级'
  } else if (val == '11') {
    text = 'B3级'
  } else if (val == '12') {
    text = 'B2级'
  } else if (val == '13') {
    text = 'B1级'
  } else if (val == '14') {
    text = 'A3级'
  } else if (val == '15') {
    text = 'A2级'
  } else if (val == '16') {
    text = 'A1级'
  } else if (val == '17') {
    text = '审核通过'
  } else if (val == '100') {
    text = '出单岗'
  } else if (val == '101') {
    text = '中级审核2'
  } else if (val == '102') {
    text = '中级审核1'
  } else if (val == '103') {
    text = '在线审核'
  } else if (val == '104') {
    text = '高级审核'
  } else if (val == '105') {
    text = '首席审核'
  }
  return text
}

export function reinsStatusJudeg(val) {
  let text = val
  if (val == 1) {
    text = '未提交再保'
  } else if (val == 2) {
    text = '已提交再保'
  } else if (val == 3) {
    text = '再保审核通过'
  } else if (val == 4) {
    text = '再保审核不通过'
  } else if (val == 0) {
    text = '默认分保'
  }
  return text
}
export function amountFun(val) {
  let num = Number(val)
  let text = ''
  if (num >= 10000) {
    text = num / 10000 + '万'
  } else {
    text = val
  }
  return text
}

//深度copy
export function deepCopy(obj) {
  let thisobj = obj;
  if (typeof thisobj === "object") {
    thisobj = JSON.parse(JSON.stringify(thisobj));
  }
  return thisobj;
}

export function formatStatus(val) {
  let text = val
  if (val == '1') {
    text = '待处理'
  } else if (val == '2') {
    text = '正在处理'
  } else if (val == '3') {
    text = '审核不通过'
  } else if (val == '4') {
    text = '已上报'
  } else if (val == '6') {
    text = '已下发(出单员)'
  } else if (val == '0') {
    text = '已处理完毕'
  } else if (val == '5') {
    text = '已撤销'
  } else if (val == '7') {
    text = '已删除'
  } else if (val == '8') {
    text = '暂存'
  }
  return text
}
// 名字超长
export function textLongHidden(val, num) {
  let text = ''
  if (!val) {
    return text
  }
  if (val.length > num) {
    text = val.slice(0, num) + '...'
  } else {
    text = val
  }
  return text
}
// 机构超长
export function comNameHidden(val) {
  let text = ''
  if (val.length > 4) {
    text = val.slice(val.length - 5, val.length) + '...'
  } else {
    text = val
  }
  return text
}

//转金额
export function toMoney(money) {
  if (money && money != null) {
    money = String(money);
    var left = money.split('.')[0],
      right = money.split('.')[1];
    right = right ? (right.length >= 2 ? '.' + right.substr(0, 2) : '.' + right + '0') : '.00';
    var temp = left.split('').reverse().join('').match(/(\d{1,3})/g);
    return (Number(money) < 0 ? "-" : "") + temp.join(',').split('').reverse().join('') + right;
  } else if (money === 0) { //注意===在这里的使用，如果传入的money为0,if中会将其判定为boolean类型，故而要另外做===判断
    return '0.00';
  } else {
    return "";
  }
}

// 日期格式控制
export function dateControl(format, date) {
  let a = ''
  let today = new Date()
  if (typeof date !== "object" && date) {
    today = new Date(Date.parse(date.replace(/-/g, "/")));
  } else {
    today = new Date(new Date());
  }
  let todayYear = today.getFullYear() //当前年
  let todayMonth = today.getMonth() + 1 //当前月
  let todayDay = today.getDate() //当前日
  let hours = today.getHours(); //当前小时
  let minute = today.getMinutes(); //当前分钟
  let second = today.getSeconds(); //当前秒
  let currentDay = new Date(todayYear, todayMonth, 0).getDate() //当前月天数
  let nextHours = new Date(today.getTime() + 30 * 60 * 1000).getHours() //现在时间的半个小时

  if (format == "yyyy-mm-dd 3") {
    if (todayDay < 10) {
      todayDay = '0' + todayDay
    }
    if (todayMonth < 10) {
      todayMonth = '0' + todayMonth
    }
    //即使启保 // 终保日期
    a = todayYear + '-' + todayMonth + '-' + todayDay
  }

  if (format == "yyyy-mm-dd 2") {
    //即使启保 // 起保日期
    if (todayDay == 1) {
      if (todayDay < 10) {
        todayDay = '0' + todayDay
      }
      // todayMonth = todayMonth - 1
      // let upDay = new Date(todayYear, todayMonth, 0).getDate() //上月天数
      if (todayMonth < 10) {
        todayMonth = '0' + todayMonth
      }
      a = (todayYear + 1) + '-' + todayMonth + '-' + todayDay
    } else {
      // todayDay = todayDay - 1
      if (todayDay < 10) {
        todayDay = '0' + todayDay
      }
      if (todayMonth < 10) {
        todayMonth = '0' + todayMonth
      }
      a = (todayYear + 1) + '-' + todayMonth + '-' + todayDay
    }
  }
  if (format == "yyyy-mm-dd 1") {
    //非即使启保 // 起保日期
    if (todayDay == currentDay) {
      todayMonth = todayMonth + 1
      if (todayMonth < 10) {
        todayMonth = '0' + todayMonth
      }
      a = todayYear + '-' + todayMonth + '-' + '01'
    } else {
      todayDay = todayDay + 1
      if (todayDay < 10) {
        todayDay = '0' + todayDay
      }
      if (todayMonth < 10) {
        todayMonth = '0' + todayMonth
      }
      a = todayYear + '-' + todayMonth + '-' + todayDay
    }
  }
  if (format == "yyyy-mm-dd 6") {
    //非即使启保 // 起保日期
    if (todayDay < 10) {
      todayDay = '0' + todayDay
    }
    if (todayMonth < 10) {
      todayMonth = '0' + todayMonth
    }
    a = todayYear + '-' + todayMonth + '-' + todayDay
  }

  if (format == "yyyy-mm-dd 4") {
    //非即使启保 // 终保日期
    if (todayDay < 10) {
      todayDay = '0' + todayDay
    }
    if (todayMonth < 10) {
      todayMonth = '0' + todayMonth
    }
    a = (todayYear + 1) + '-' + todayMonth + '-' + todayDay
  }

  if (format == "yyyy-mm-dd 5") {
    //非即使启保 // 终保日期
    if (todayDay == 1) {
      todayMonth = todayMonth - 1
      if (todayMonth < 10) {
        todayMonth = '0' + todayMonth
      }
      let nexcurrentDay = new Date(todayYear, todayMonth, 0).getDate()
      a = (todayYear + 1) + '-' + todayMonth + '-' + nexcurrentDay
    } else {
      todayDay = todayDay - 1
      if (todayDay < 10) {
        todayDay = '0' + todayDay
      }
      if (todayMonth < 10) {
        todayMonth = '0' + todayMonth
      }
      a = (todayYear + 1) + '-' + todayMonth + '-' + todayDay
    }
  }

  if (format == 'hh') {
    a = nextHours + 1
  }
  if (format == 'hh 2') {
    a = hours
  }
  if (format == 'hh 3') {
    hours = hours < 10 ? '0' + hours : hours
    minute = minute < 10 ? '0' + minute : minute
    a = hours + ':' + minute
  }
  return a
}

//单程提车日期
export function dateControlYearDays(val) {
  let a = []
  let today = new Date()
  let todayYear = today.getFullYear() //当前年
  let todayMonth = today.getMonth() + 1 //当前月
  let todayDay = today.getDate() //当前日
  let todayDayTime = new Date(todayYear + '/' + todayMonth + '/' + todayDay + ' 23:59:59').getTime()
  let lastDay = todayDayTime + (3600 * 24 * 1000)
  let newLastData = lastDay + 3600 * 24 * 1000 * val
  a = [new Date(lastDay).format('yyyy-MM-dd 00:00:00'), new Date(newLastData).format('yyyy-MM-dd 23:59:59')]
  return a
}

// 一年时间
export function yearTime() {
  let data = []
  let newDate = new Date().getTime()
  let time = new Date(newDate); //现在时间
  let year = time.getFullYear(); //当前年
  let month = time.getMonth() + 1; //当前月
  let day = time.getDate(); //当前天
  let lastMonth = month - 1; //上月
  let lastDay = new Date(year, lastMonth, 0).getDate(); //上月天数
  let newDay = new Date(year, month, 0).getDate(); //当月天数
  if (day == 1) {
    if (day < 10) {
      day = '0' + day
    }
    if (month == 1) {
      if (month < 10) {
        month = '0' + month
      }
      data = [year + '-' + month + '-' + day, (year + 1) + '-' + '12' + '-' + '31']
    } else {
      if (month < 10) {
        month = '0' + month
      }
      data = [year + '-' + month + '-' + day, (year + 1) + '-' + lastMonth + '-' + lastDay]
    }
  } else {
    if (month < 10) {
      month = '0' + month
    }
    data = [year + '-' + month + '-' + (day < 10 ? '0' + day : day), (year + 1) + '-' + month + '-' + (day - 1 < 10 ? '0' + (day - 1) : (day - 1))]
  }

  return data
}

//新车上牌
export function plateType(val, data) {
  let text = '无';
  data.map(item => {
    if (val == item.code) {
      text = item.value;
    }
  });
  return text;
}

// 两个时间相差的月数
export function getDaysBetween(dateString1, dateString2) {
  var startDate = Date.parse(dateString1.replace(/-/g, "/"));
  var endDate = Date.parse(dateString2.replace(/-/g, "/"));
  var days = (endDate - startDate) / (1 * 24 * 60 * 60 * 1000);
  days = days + 1;
  return days;
}